﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Entity;

namespace Web.admin.CompetitionManage.Phases
{
    public partial class AddPhases : System.Web.UI.Page
    {
        PhaseService PhasesService = new PhaseService();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string operation = Request["OPERATION"];
                if (operation == null)
                    return;
                string PhasesId = Request["PHA_ID"];
                if (PhasesId == null)
                    return;

                if (operation == "Modify")
                {
                    ModifyPhases(PhasesId);
                }
                else if (operation == "Delete")
                {
                    DeletePhases(PhasesId);
                }
            }

        }

        protected void ModifyPhases(string PhasesId)
        {
            BoPhases Phases = PhasesService.getPhase(PhasesId);
            PHA_NAMEBOX.Value = Phases.PHA_ID;
            TextBoxName.Text = Phases.PHA_NAME;
            TextBoxCnrtitle.Text = Phases.PHA_CNRTITLE;
            KindEditor.Text = Phases.PHA_CONTENT;
            TextBoxMethod.Text = Phases.PHA_METHOD;
        }

        protected void DeletePhases(string PhasesId)
        {
            BoPhases Phases = new BoPhases();
            Phases.PHA_ID = PhasesId;
            PhasesService.DeletePhase(Phases);
            Response.Redirect("ListPhases.aspx");
        }

        protected void ButtonOK_Click(object sender, EventArgs e)
        {
            if (PHA_NAMEBOX.Value == "")
            {
                BoPhases Phases = new BoPhases();
                Phases.PHA_NAME = TextBoxName.Text;
                Phases.PHA_CNRTITLE = TextBoxCnrtitle.Text;
                Phases.PHA_CONTENT = KindEditor.Text;
                Phases.PHA_METHOD = TextBoxMethod.Text;
                PhasesService.CreatePhase(Phases);
                Response.Redirect("ListPhases.aspx");
            }
            else
            {
                BoPhases Phases = new BoPhases();
                Phases.PHA_ID = PHA_NAMEBOX.Value;
                Phases.PHA_NAME = TextBoxName.Text;
                Phases.PHA_CONTENT = KindEditor.Text;
                Phases.PHA_CNRTITLE = TextBoxCnrtitle.Text;
                Phases.PHA_METHOD = TextBoxMethod.Text;
                PhasesService.UpdatePhase(Phases);
                Response.Redirect("ListPhases.aspx");
            }
        }
    }
}